import java.util.ArrayList;
import java.util.List;

/**
 * @program: LeetCode
 * @description: LeetCode : 剑指 Offer 57 - II. 和为s的连续正数序列
 * @author: WXY
 * @create: 2022-12-10 21:55
 * @Version 1.0
 **/


public class Num057_2_findContinuousSequence {
    public static int[][] findContinuousSequence(int target) {
        int left = 1;
        int right  = 2;
        List<int[]> list = new ArrayList<>();
        while (left < right) {
            int sum = (right - left + 1) * (left + right) / 2;
            if (sum == target) {
                int[] temp = new int[right - left + 1];
                for (int i = 0; i < temp.length; i++) {
                    temp[i] = left + i;
                }
                list.add(temp);
                left++;
            } else if (sum < target) {
                right++;
            }else {
                left++;
            }
        }
        return list.toArray(new int[list.size()][]);
    }

    public static void main(String[] args) {
        int[][] arr = findContinuousSequence(9);
        System.out.println(arr);

    }
}
